﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class MovementDA : IMovementDA
    {
        private string APPROVED_BY = "@APPROVED_BY";
        private string APPROVED_DATE = "@APPROVED_DATE";
        private string CREATED_BY = "@CREATED_BY";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string MOVEMENT_DATE = "@MOVEMENT_DATE";
        private string MOVEMENT_ID = "@MOVEMENT_ID";
        private string MOVEMENT_TYPE = "@MOVEMENT_TYPE";
        private string OWNER_ID = "@OWNER_ID";
        private string REASON_CODE = "@REASON_CODE";
        private string REMARK = "@REMARK";
        private string SQL_CHECK_MOVEMENT_ID_UNIQUE = " SELECT COUNT(1) FROM @_@MOVEMENT WHERE MOVEMENT_ID = @MOVEMENT_ID ";
        private string SQL_DELETE_MOVEMENT = " DELETE FROM @_@MOVEMENT WHERE MOVEMENT_ID = @MOVEMENT_ID ";
        private string SQL_INSERT_MOVEMENT = " INSERT INTO @_@MOVEMENT ( WH_ID, MOVEMENT_ID, OWNER_ID, MOVEMENT_DATE, MOVEMENT_TYPE, REASON_CODE, APPROVED_BY, APPROVED_DATE, STATUS, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @MOVEMENT_ID, @OWNER_ID, @MOVEMENT_DATE, @MOVEMENT_TYPE, @REASON_CODE, @APPROVED_BY, @APPROVED_DATE, @STATUS, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_MOVEMENT = " SELECT  ROWID, WH_ID, MOVEMENT_ID, OWNER_ID, MOVEMENT_DATE, MOVEMENT_TYPE, REASON_CODE, APPROVED_BY, APPROVED_DATE, STATUS, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, IS_ACTIVE, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE  FROM  @_@MOVEMENT ";
        private string SQL_SELECT_ALL_MOVEMENT_LANGUAGE = " SELECT  M.ROWID, M.WH_ID, M.MOVEMENT_ID, M.OWNER_ID, M.MOVEMENT_DATE, M.MOVEMENT_TYPE, M.REASON_CODE, M.APPROVED_BY, M.APPROVED_DATE, M.STATUS, T.[TEXT] AS STATUS_D,  M.UDF1, M.UDF2, M.UDF3, M.UDF4, M.UDF5, M.UDF6, M.UDF7, M.UDF8, M.UDF9, M.UDF10, M.REMARK, M.IS_ACTIVE, M.TS, M.CREATED_BY, M.CREATED_DATE, M.UPDATED_BY, M.UPDATED_DATE    FROM  @_@MOVEMENT M  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = M.STATUS AND SCD.SYS_CODE_TYPE = 'MovementStatus'   LEFT JOIN sysadm.TRANSLATION T ON 'MovementStatus.'+M.STATUS = T.ITEM_ID   AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE";
        private string SQL_UPDATE_MOVEMENT = " UPDATE @_@MOVEMENT SET WH_ID = @WH_ID, OWNER_ID = @OWNER_ID, MOVEMENT_DATE = @MOVEMENT_DATE, MOVEMENT_TYPE = @MOVEMENT_TYPE, REASON_CODE = @REASON_CODE, APPROVED_BY = @APPROVED_BY, APPROVED_DATE = @APPROVED_DATE, STATUS = @STATUS, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE MOVEMENT_ID = @MOVEMENT_ID  ";
        private string SQL_UPDATE_MOVEMENT_SATAUS_ = " UPDATE @_@MOVEMENT SET STATUS =@STATUS,UPDATED_BY=@UPDATED_BY,UPDATED_DATE=GetDate() WHERE MOVEMENT_ID= @MOVEMENT_ID";
        private string SQL_UPDATE_SATAUS = " UPDATE @_@MOVEMENT SET STATUS =@STATUS,APPROVED_BY=@APPROVED_BY,APPROVED_DATE=GetDate() WHERE MOVEMENT_ID= @MOVEMENT_ID";
        private string STATUS = "@STATUS";
        private string TS = "@TS";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckMovementIDUnique(string movementID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_MOVEMENT_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckMovementIDUnique(DataBase dataBase, DbTransaction tran, string movementID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_MOVEMENT_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteMovement(List<string> movementID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int j = 0; j < movementID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteMovement(DataBase dataBase, DbTransaction tran, List<string> movementID, string whLoginID)
        {
            int result = 0;
            try
            {
                for (int j = 0; j < movementID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllMovement(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_MOVEMENT.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllMovement(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_MOVEMENT.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public MovementInfo GetMovementByID(string movementID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_MOVEMENT.Replace("@_@", whLoginID) + " WHERE MOVEMENT_ID = @MOVEMENT_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID) };
            MovementInfo movementInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    DateTime CS00003;
                    movementInfo = new MovementInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["MOVEMENT_ID"].ToString(), reader["OWNER_ID"].ToString(), (reader["MOVEMENT_DATE"].ToString() != "") ? DateTime.Parse(reader["MOVEMENT_DATE"].ToString()) : (CS00003 = new DateTime()), reader["MOVEMENT_TYPE"].ToString(), reader["REASON_CODE"].ToString(), reader["APPROVED_BY"].ToString(), (reader["APPROVED_DATE"].ToString() != "") ? DateTime.Parse(reader["APPROVED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return movementInfo;
        }

        public MovementInfo GetMovementByID(DataBase dataBase, DbTransaction tran, string movementID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_MOVEMENT.Replace("@_@", whLoginID) + " WHERE MOVEMENT_ID = @MOVEMENT_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID) };
            MovementInfo movementInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                DateTime CS00003;
                movementInfo = new MovementInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["MOVEMENT_ID"].ToString(), reader["OWNER_ID"].ToString(), (reader["MOVEMENT_DATE"].ToString() != "") ? DateTime.Parse(reader["MOVEMENT_DATE"].ToString()) : (CS00003 = new DateTime()), reader["MOVEMENT_TYPE"].ToString(), reader["REASON_CODE"].ToString(), reader["APPROVED_BY"].ToString(), (reader["APPROVED_DATE"].ToString() != "") ? DateTime.Parse(reader["APPROVED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return movementInfo;
        }

        public DataSet GetMovementByQueryList(List<string> sqlWhere, MovementQueryEntity movementQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_MOVEMENT_LANGUAGE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!movementQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, movementQuery.CurrentPage, movementQuery.PageSize, movementQuery.SortField, movementQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetMovementByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, MovementQueryEntity movementQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_MOVEMENT_LANGUAGE.Replace("@_@", whLoginID).Replace("@LANGUAGE", pubParasInfo.UserLanguage);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!movementQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, movementQuery.CurrentPage, movementQuery.PageSize, movementQuery.SortField, movementQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertMovement(MovementInfo movementInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                movementInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Movement_Parameters(movementInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertMovement(DataBase dataBase, DbTransaction tran, MovementInfo movementInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                movementInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Movement_Parameters(movementInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_Movement_Parameters(MovementInfo movementInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.MOVEMENT_ID, SqlDbType.VarChar, 20), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.MOVEMENT_DATE, SqlDbType.DateTime, 8), new SqlParameter(this.MOVEMENT_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.REASON_CODE, SqlDbType.VarChar, 20), new SqlParameter(this.APPROVED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.APPROVED_DATE, SqlDbType.DateTime, 8), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), 
                new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 0x3e8), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(movementInfo.WhID))
            {
                paramArray[0].Value = movementInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = movementInfo.MovementID;
            paramArray[2].Value = movementInfo.OwnerID;
            paramArray[3].Value = movementInfo.MovementDate;
            paramArray[4].Value = movementInfo.MovementType;
            paramArray[5].Value = movementInfo.ReasonCode;
            paramArray[6].Value = movementInfo.ApprovedBy;
            paramArray[7].Value = movementInfo.ApprovedDate;
            paramArray[8].Value = movementInfo.Status;
            if (!string.IsNullOrEmpty(movementInfo.Udf1))
            {
                paramArray[9].Value = movementInfo.Udf1;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf2))
            {
                paramArray[10].Value = movementInfo.Udf2;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf3))
            {
                paramArray[11].Value = movementInfo.Udf3;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf4))
            {
                paramArray[12].Value = movementInfo.Udf4;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf5))
            {
                paramArray[13].Value = movementInfo.Udf5;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf6))
            {
                paramArray[14].Value = movementInfo.Udf6;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf7))
            {
                paramArray[15].Value = movementInfo.Udf7;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf8))
            {
                paramArray[0x10].Value = movementInfo.Udf8;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf9))
            {
                paramArray[0x11].Value = movementInfo.Udf9;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Udf10))
            {
                paramArray[0x12].Value = movementInfo.Udf10;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(movementInfo.Remark))
            {
                paramArray[0x13].Value = movementInfo.Remark;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            paramArray[20].Value = movementInfo.IsActive;
            paramArray[0x15].Value = movementInfo.CreatedBy;
            paramArray[0x16].Value = movementInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateMovement(MovementInfo movementInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                movementInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Movement_Parameters(movementInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateMovement(DataBase dataBase, DbTransaction tran, MovementInfo movementInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                movementInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Movement_Parameters(movementInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_MOVEMENT.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateMovementStatus(DataBase dataBase, DbTransaction tran, string status, string movementID, string AppovedBy, string whLoginID)
        {
            int result = 0;
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID), new SqlParameter("@STATUS", status), new SqlParameter("@APPROVED_BY", AppovedBy) };
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_SATAUS.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateMovementStatus2(DataBase dataBase, DbTransaction tran, string status, string movementID, string updatedBy, string whLoginID)
        {
            int result = 0;
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@MOVEMENT_ID", movementID), new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy) };
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_MOVEMENT_SATAUS_.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

